package com.dahua.messagesyncsh.controller;

import com.dahua.messagesyncsh.common.result.ResultVO;
import com.dahua.messagesyncsh.criteria.CollectionQueryCriteria;
import com.dahua.messagesyncsh.entity.Collection;
import com.dahua.messagesyncsh.pojo.Alarm;
import com.dahua.messagesyncsh.pojo.Control56;
import com.dahua.messagesyncsh.pojo.Recovery;
import com.dahua.messagesyncsh.pojo.T485;
import com.dahua.messagesyncsh.service.CollectionService;
import com.dahua.messagesyncsh.service.ProcessorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;

@Slf4j
@RestController
@RequestMapping("/shdt/AlarmRecord")
public class ShaController {
    @Resource
    private CollectionService collectionService;

    @PostMapping("/pushDataAlarm")
    public ResultVO<?> alarm(@RequestBody Alarm data) {
        log.info("收到报警数据：{}", data);
        return new ResultVO<>("ok");
    }

    @PostMapping("/handleDataAlarm")
    public ResultVO<?> recovery(@RequestBody Recovery data) {
        log.info("收到恢复数据：{}", data);
        return new ResultVO<>("ok");
    }

    @GetMapping("/collection")
    public ResultVO<?> collection() {
        return new ResultVO<>(collectionService.enquire(new CollectionQueryCriteria()));
    }



    @Resource
    private ProcessorService processorService;

    @PostMapping("/control56")
    public ResultVO<?> addCollection(@RequestBody T485 t485) {

        processorService.handleT485(Collections.singletonList(t485));

        return new ResultVO<>("ok");
    }
}

